import QtQuick 2.0

Item {
    id: groceryEntry
    property string imageUrl
    property string brand
    property string productName
    property string size
    property int quantity: 1
    property real price

    width: parent.width
    height: entryHeight

    Row {
        height: parent.height
        spacing: 10
        anchors.horizontalCenter: parent.horizontalCenter

        Text {
            text: quantity + "x"
            font.pointSize: 18
            font.family: "Verdana"
            font.bold: true
            anchors.verticalCenter: imgRect.verticalCenter
        }

        Column {
            anchors.verticalCenter: imgRect.verticalCenter
            spacing: 5
            Rectangle {
                id: plusRect
                width: 15
                height: 15
                color: "white"
                border.color: "black"
                border.width: 1
                Text {
                    text: "+"
                    font.pointSize: 12
                    font.family: "Verdana"
                    font.bold: true
                    anchors.fill: parent
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter

                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            quantity = quantity + 1
                            groceriesContent.estCost = groceriesContent.estCost + price
                            groceriesContent.estCost = groceriesContent.estCost.toFixed(2);
                        }
                    }
                }
            }

            Rectangle {
                id: minusRect
                width: 15
                height: 15
                color: "white"
                border.color: "black"
                border.width: 1
                Text {
                    text: "-"
                    font.pointSize: 12
                    font.family: "Verdana"
                    font.bold: true
                    anchors.fill: parent
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter

                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            if (quantity != 1) {
                                quantity = quantity - 1
                                groceriesContent.estCost = groceriesContent.estCost - price
                                groceriesContent.estCost = groceriesContent.estCost.toFixed(2);
                            }
                        }
                    }
                }
            }
        }

        Rectangle {
            id: imgRect
            width: 84
            height: 84
            color: "transparent"
            border.color: content.border.color
            border.width: 2

            Image {
                id: img
                height: 80
                anchors.centerIn: parent
                source: imageUrl
                fillMode: Image.PreserveAspectFit
            }
        }

        Column {
            id: entry
            spacing: 5
            y: 10
            width: 700
            // Product name
            Text {
                text: productName
                font.pointSize: 20
                font.family: "Verdana"
            }

            Row {
                width: productName.paintedWidth
                spacing: 100

                Column {
                    id: brandSizeCol
                    // Brand
                    Text {
                        text: "by " + brand
                        font.pointSize: 15
                        font.family: "Verdana"
                        font.italic: true
                        color: "grey"
                    }

                    // size
                    Text {
                        text: "Size: " + size
                        font.pointSize: 12
                        font.family: "Verdana"
                        color: "grey"
                    }
                }

                // Price
                Text {
                    text: "Avg Price: $" + price
                    font.pointSize: 18
                    font.family: "Verdana"
                    font.bold: true
                    horizontalAlignment: Text.AlignRight
                    anchors.verticalCenter: brandSizeCol.verticalCenter
                }
            }
        }

        Image {
            y: 20
            height: 40
            fillMode: Image.PreserveAspectFit
            source: "images/binBlack.png"

            MouseArea {
                anchors.fill: parent
                onClicked: {
                    groceriesContent.estCost = groceriesContent.estCost - quantity * price
                    groceriesContent.estCost = groceriesContent.estCost.toFixed(2);
                    groceryEntry.destroy();
                }
            }
        }
    }
}
